#!/usr/bin/env lua

local FL = require "functional.infinite_list"

l = FL.iterate(function (x) return x+1 end, 1)

assert( l[10] == 10)

l = FL.repeated(42)
assert( l[1] == 42 and l[2] == 42 and l[99] == 42 and l[-101] == 42)


l = FL.replicate(3, 98)
assert( l[0] == nil and l[1] == 98 and l[3] == 98 and l[4] == nil and l[99] == nil)


--[[
    cycle :: [a] -> [a]

    cycle ties a finite list into a circular one, or equivalently, the
    infinite repetition of the original list.
]]--

l = { 1, 2, 3 }
l = FL.cycle(l)

assert(l[1] == 1)
assert(l[2] == 2)
assert(l[3] == 3)
assert(l[4] == 1)
assert(l[5] == 2)
assert(l[6] == 3)
assert(l[7] == 1)
assert(l[8] == 2)
assert(l[9] == 3)


print("All tests passed.")

